<template>
  <div class="current pt-re">
  </div>
  <div class="userInfo" @click="login()">
    <div class="avator">
      <img :src="userInfo.avatar" alt="" />
    </div>
    <div class="self-info">
      <div class="name">{{ userInfo.name }}</div>
      <div class="service">{{ userInfo.service }}</div>
    </div>
    <div class="arrow-right">
      <van-icon name="arrow" size="20" color="#979797" />
    </div>
  </div>
</template>

<script setup>
import { getAssetURL } from "@/utils/load_assets.js"
import { getRegionservice } from "@/services";
import { reactive } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from "vue";
import useMainStore from '@/stores/modules/main';
import { storeToRefs } from 'pinia';
const router = useRouter()
let localInfo = localStorage.getItem('userinfo3')
let token = localInfo ? JSON.parse(localInfo).token : ''
const mainStore = useMainStore()
const { userInfo } = storeToRefs(mainStore)
onMounted(async () => {
  if (token) {
    let res = await getRegionservice()
    userInfo.value.name = res.data.name
    userInfo.value.service = res.data.mobile
    res.data.avatar?userInfo.value.avatar = res.data.avatar:''
  }
})
const login = () => {
  token = localStorage.getItem('userinfo3') ? JSON.parse(localInfo).token : ''
  if (!token) {
    router.push({
      path: '/login',
    })
    return
  }
  router.push({
    path: '/userCenter',
  })
}
</script>

<style lang="scss" scoped>
.current {
  background: linear-gradient(to bottom, #b0e9e105 7%, rgb(44 185 164 / 15%), #fff);
  background-size: 100% 100%;
  height: 160px;
  background-repeat: no-repeat;
  width: 100%;
  position: absolute;
}

.userInfo {
  padding: 0px 20px;
  margin-top: 50px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  position: relative;
  z-index: 1;

  .avator {
    height: 60px;
    width: 60px;

    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
    }
  }

  .self-info {
    margin-left: 20px;

    .name {
      color: #081738;
      font-family: PingFang SC;
      font-size: 18px;
      font-style: normal;
      font-weight: 500;
    }

    .service {
      color: #545454;
      font-family: PingFang SC;
      font-size: 12px;
      font-style: normal;
      font-weight: 400;
      margin-top: 10px;
    }
  }

  .arrow-right {
    flex: 1;
    text-align: right;
  }
}
</style>